<?php

namespace App\Models;

use Core\Result\Result;
use Core\Sign\Sign;
use Core\Utils\Ip\Ipinit;

class RechargeModel
{
    /**
     * 查询充值
     * entry conn,id
     * return array
     * */
    public static function getRechargeInsideId($conn,$id){
        $querySql="SELECT `id`,`uid`,`serial`,`proof`,`amount`,`notes`,`time`,`state` FROM `recharge` WHERE  `id` = $id";
        return $conn->readConn($querySql);
    }
    /**
     * 查询充值列表
     * entry conn,Recharge
     * return array
     * */
    public static function getRechargeListInside($conn,$Recharge){
        $querySql="SELECT `id`,`uid`,`serial`,`proof`,`amount`,`notes`,`time`,`state` FROM `recharge` WHERE  `uid` = $Recharge->uid order by id desc";
        return $conn->readConn($querySql,true);
    }
    /**
     * 添加充值记录
     * entry
     * return int
     * */
    public static function insertRecharge($conn,$Recharge){
        $insertSql ="INSERT INTO `recharge`(`uid`,`serial`,`proof`,`amount`,`notes`,`time`) VALUES ($Recharge->uid,'$Recharge->serial','$Recharge->proof',$Recharge->amount,'$Recharge->notes',NOW())";
        return $conn->executeConn($insertSql);
    }
    /**
     * 修改充值
     * entry AssetExample
     * return int
     * */
    public static function editRechargeInside($conn,$Example){
        $joinSql="";
        if($Example->amount !=null){
            $joinSql.=" `amount` = '$Example->amount',";
        }
        if($Example->state !=null){
            $joinSql.=" `state` = '$Example->state',";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `recharge` SET $innerJoin WHERE `id` = $Example->id";
            return $conn->executeConn($upUserSql);
        }
    }
}